package net.huashitong.synthetical.newSupervision.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.newSupervision.entity.UnitPersonnel;
import net.huashitong.synthetical.newSupervision.filter.UnitPersonnelFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/7/15
 * Time: 11:27
 * To change this template use File | Settings | File Templates.
 * Description:
 */

@Repository
public class UnitPersonnelDao extends StringDao<UnitPersonnel> {

    /**
     * 条件查询主入口
     * @param filter
     * @return
     */
    public List<UnitPersonnel> queryFilter(UnitPersonnelFilter filter) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getDeptId())){
            query.append(" and deptId=:deptId").setParam("deptId",filter.getDeptId() );
        }

        if (StringUtils.isNotBlank(filter.getDeptName())){
            query.append(" and deptName like:deptName").setParam("deptName",StringUtils.getLikewords(filter.getDeptName()));
        }

        if (StringUtils.isNotBlank(filter.getName())){
            query.append(" and name like:name").setParam("name", filter.getName());
        }
        if (StringUtils.isNotBlank(filter.getPhone())){
            query.append(" and phone like:phone").setParam("phone",filter.getPhone());
        }
        return query.listResult(filter);
    }
}
